import os
import fitz

doc = fitz.open("E:\\Project\\OpenSource\\windows\\C++\\mupdf-1.17.0-source\\platform\\win32\\x64\\Debug\\程辉-转正答辩PPT.pdf")

if doc.pageCount > 0:

    font_visited = []
    num = 0

    for pg in range(doc.pageCount):
        page = doc[pg]
        pageFonts = page.getFontList()
        for font in pageFonts:
            if font[0] in font_visited:
                continue

            font_visited.append(font[0])

            basename, ext, _, buffer = doc.extractFont(font[0])

            if ext != "n/a":
                num += 1
                fontname = "%s-%i.%s" % (basename, font[0], ext)
                with open(fontname, "wb") as fout:
                    fout.write(buffer)
                print("extracted", fontname)

footer = "extracted %i font files from %s." % (num, doc.name)
footer_line = "-".ljust(len(footer), "-")

# output some protocol
print(footer_line)
print(footer)
print(footer_line)

# Close the PDF
doc.close()